package cn.didi.feidi.androidorder.assembly;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.os.Build;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.annotation.StyleRes;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;

import cn.didi.feidi.androidorder.R;
import cn.didi.feidi.androidorder.databinding.ViewPayWordKeyboardBinding;

/**
 * Created by jinxiong on 2017/8/29.
 */
//FeiDiKeyboardTextView.Callback
public class FeiDiKeyboardView extends FrameLayout {

    ViewPayWordKeyboardBinding binding;


    public FeiDiKeyboardView(@NonNull Context context) {
        this(context, null);
    }

    public FeiDiKeyboardView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public FeiDiKeyboardView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context, attrs, defStyleAttr);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public FeiDiKeyboardView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initView(context, attrs, defStyleAttr);
    }

    private void initView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        binding = DataBindingUtil.inflate(inflater, R.layout.view_pay_word_keyboard, this, true);
    }


    public void setClearListener(OnClickListener clearListener) {

        binding.keyboardClearIv.setOnClickListener(clearListener);

    }


    public void setCallback(FeiDiKeyboardTextView.Callback callback) {


        binding.keyboard1.setCallback(callback);
        binding.keyboard2.setCallback(callback);
        binding.keyboard3.setCallback(callback);

        binding.keyboard4.setCallback(callback);
        binding.keyboard5.setCallback(callback);
        binding.keyboard6.setCallback(callback);

        binding.keyboard7.setCallback(callback);
        binding.keyboard8.setCallback(callback);
        binding.keyboard9.setCallback(callback);

        binding.keyboard0.setCallback(callback);

    }
}
